//
//  ViewController.m
//  UI05_UIControl及子类
//
//  Created by Scott on 16/5/9.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "ViewController.h"
#import "SimpleSlider.h"
#import "SimpleSwitch.h"
#import "SimpleSegement.h"
#import "SimplePageControl.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createSwitch];
    [self createSlide];
    [self creatSegment];
    [self createPage];
    
}

#pragma mark - 知识点1: UISwitch
- (void)createSwitch {
    
    // Create obj
    SimpleSwitch *swi = [[SimpleSwitch alloc] initWithFrame:CGRectMake(120, 50, 100, 100)];
    
    [self.view addSubview:swi];
    [swi release];
    
    
    // target_action
    [swi addTarget:self action:@selector(handleSwitch:) forControlEvents:UIControlEventValueChanged];
}

- (void)handleSwitch:(SimpleSwitch *)swi {
    
    if (swi.on) {
        
        self.view.backgroundColor = [UIColor yellowColor];
    } else {
        
        self.view.backgroundColor = [UIColor whiteColor];
    }
}


#pragma mark - 知识点2: UISlide
- (void)createSlide {
    
    SimpleSlider *slider = [[SimpleSlider alloc] initWithFrame:CGRectMake(100, 120, 200, 40)];
    [self.view addSubview:slider];
    [slider release];
    
    // value
    slider.minimumValue = 1;
    slider.maximumValue = 100;
    
    // target_action
    [slider addTarget:self action:@selector(handleSlide:) forControlEvents:UIControlEventValueChanged];
    
}
- (void)handleSlide:(SimpleSlider *)slider {
    
    
    self.view.alpha = slider.value / 100.0f;
    
}


#pragma mark - 知识点3: UISegmentControl
- (void)creatSegment {
    
    SimpleSegement *segement = [[SimpleSegement alloc] initWithItems:@[@"红", @"黄", @"蓝"]];
    
    segement.frame = CGRectMake(20, 180, 300, 40);
    [self.view addSubview:segement];
    [segement release];
    
    segement.selectedSegmentIndex = 0;
    self.view.backgroundColor = [UIColor redColor];
    
    [segement addTarget:self action:@selector(handleSegment:) forControlEvents:UIControlEventValueChanged];

}

- (void)handleSegment:(SimpleSegement *)segement {
    
    switch (segement.selectedSegmentIndex) {
        case 0:
            self.view.backgroundColor = [UIColor redColor];
            break;
            
        case 1:
            self.view.backgroundColor = [UIColor yellowColor];
            break;
        case 2:
            self.view.backgroundColor = [UIColor blueColor];
            break;
        default:
            break;
    }
    
    
    
    
    
}


#pragma mark - 知识点4: UIPageControl
- (void)createPage {
    
    SimplePageControl *page = [[SimplePageControl alloc] initWithFrame:CGRectMake(20, 300, 100, 40)];
    [self.view addSubview:page];
    [page release];
    
    page.backgroundColor = [UIColor blackColor];
    
    page.numberOfPages = 5;
    page.currentPage = 2;
    
    [page addTarget:self action:@selector(handlePage:) forControlEvents:UIControlEventValueChanged];
}

- (void)handlePage:(SimplePageControl *)page {
    
    
    
}









@end
